package web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import biz.DeptBiz;
import biz.UserBiz;
import dto.UserDto;
import entity.Dept;

public class SearchUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public SearchUserServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String curpage = request.getParameter("curpage");
		String name = request.getParameter("name");
		String sex = request.getParameter("sex");
		String beginage = request.getParameter("beginage");
		String endage = request.getParameter("endage");
		String did = request.getParameter("did");
		UserBiz userBiz = new UserBiz();
		List<UserDto> list = userBiz.searchUser(name, sex, beginage, endage, did, Integer.parseInt(curpage));
		int page = userBiz.searchPageCount(name, sex, beginage, endage, did);
		request.setAttribute("list", list);
		request.setAttribute("page", page);
		
		DeptBiz deptBiz = new DeptBiz();
		List<Dept> deptlist = deptBiz.selectAllDept();
		request.setAttribute("deptlist", deptlist);
				
		request.getRequestDispatcher("SearchUser.jsp").forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
